// pages/mine/mine.js
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    username: '无网路链接',
    userhead: '',
    carcount: 0,
    couponcount:0,
    isHideBind:true,
    waitNum_type:true,         //带付款小红点
    waitNum:0,
    waitSend_type:true,
    waitSend:0,
    overSend_type:true,
    overSend:0,
    overState_type:true,
    overState:0,
    dengjiIcon:'',
    level:'',                //等级
    isShowMvp:true
  },
  // 跳转购物车
  toCar: function () {
    wx.navigateTo({
      url: '/pages/shopcar/shopcar',
    })
  },
  // 跳转我的推荐
  toRecommend:function(){
    wx.navigateTo({
      url: '/pages/recommend/recommend',
    })
  },
  //跳转我的优惠券
  toMyCoupon:function(){
    wx.navigateTo({
      url: '/pages/couponlist/couponlist',
    })
  },
  //跳到订单列表
  toOrderList: function () {
    var state = 0
    wx.navigateTo({
      url: '/pages/orderlist/orderlist?state=' + state,
    })
  },

  toWaitPay:function(){
    var state=0
    wx.navigateTo({
      url: '/pages/orderlist/orderlist?state='+state,
    })
  },
  toWaitSend: function(){
    var state = 1
    wx.navigateTo({
      url: '/pages/orderlist/orderlist?state=' + state,
    })
  },
  toSureGet: function(){
    var state = 2
    wx.navigateTo({
      url: '/pages/orderlist/orderlist?state=' + state,
    })
  },

  toComplety:function(){
    var state = 3
    wx.navigateTo({
      url: '/pages/orderlist/orderlist?state=' + state,
    })
  },

  // 我的钱包
  toPurse:function(){
    wx.navigateTo({
      url: '/pages/purse/purse',
    })
  },

  //我的优惠券
  toMyCoupon:function(){
    wx.navigateTo({
      url: '/pages/couponlist/couponlist',
    })
  },
  toSkill(){
    wx.navigateTo({
      url: '/pages/skill/skill',
    })
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
    wx.setNavigationBarTitle({
      title: '我的'
    })

  },
  // 绑定手机号
  btnBind: function () {
    this.bindPhone.showBind();
  },

  // 头像点击
  head_click:function(){
    wx.navigateTo({
      url: '/pages/mvpinfo/mvpinfo',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var self = this;
    var url = app.serverUrl + 'About/personalCenter';
    wx.request({
      url: url,
      method: 'post',
      data: {
        openid: app.openid,
      },
      success: function (res) {
        var data = res.data.data;
        console.log(res);
        self.setData({
          // carcount: data.carcount,
          // couponcount: data.couponcount,
          username: app.globalData.userInfo.nickName,
          userhead: app.globalData.userInfo.avatarUrl,
        })
        // 等级
        console.log('等级',data.level)
        switch (data.level){
          case -1:
             self.setData({
               dengjiIcon: ''
             })
             break;
          case 0:
          self.setData({
            dengjiIcon: '/image/putong.png'
          })
            break;
          case 1:
            self.setData({
              dengjiIcon: '/image/gaongji.png'
            })
            break;
          case 2:
            self.setData({
              dengjiIcon: '/image/baiyin.png'
            })
            break;
          case 3:
            self.setData({
              dengjiIcon: '/image/huangjin.png'
            })
            break;
          case 4:
            self.setData({
              dengjiIcon: '/image/zhuanshi.png'
            })
            break;
        }
        // 未付款
        if (data.orderwfk > 0) {
          self.setData({
            waitNum_type: false,         //带付款小红点
            waitNum: data.orderwfk,
          })
        }else{
          self.setData({
            waitNum_type: true,         //带付款小红点
          })
        }
        // 待发货
        if (data.orderdfh > 0) {
          self.setData({
            waitSend_type: false,
            waitSend: data.orderdfh,
          })
        } else {
          self.setData({
            waitSend_type: true,         //带付款小红点
          })
        }
        //待收货
        if (data.orderdfk > 0) {
          self.setData({
            overSend_type: false,
            overSend: data.orderdfk
          })
        } else {
          self.setData({
            overSend_type: true,         //带付款小红点
          })
        }
        wx.hideLoading()
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '大易益·传统文化大舞台，爱好者的掌中宝！',
      path: '/pages/index/index'
    }
  }
  
})